package com.recommendation.action;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.recommendation.taobao.TaobaoProxy;
import com.taobao.api.ApiException;

@Results({
	@Result(name="success", type="httpheader"),
	@Result(name="error", type="httpheader", params={"headers.msg", "error"})
})
public class UnrecommendAction extends ActionBase{

	private String numIids;

	public String execute()
	{
		String sessionKey = getSessionId();
		if (numIids != null)
		{
			String[] numIidArray = StringUtils.split(numIids, ',');
			for (String numIid : numIidArray)
			{
				try {
					TaobaoProxy.deleteRecommendItem(Long.parseLong(numIid), sessionKey);
					return SUCCESS;
				} catch (NumberFormatException e) {
					error(e);
				} catch (ApiException e) {
					error(e);
				}
			}
		}
		return ERROR;
	}
	
	public String getNumIids() {
		return numIids;
	}

	public void setNumIids(String numIids) {
		this.numIids = numIids;
	}
}
